<template>
  <div>
    <el-card>
      <el-form ref="camerist" :model="camerist" label-width="80px">
        <el-form-item label="电话">
          <el-input disabled v-model="camerist.phone" type="text"></el-input>
        </el-form-item>
        <el-form-item label="邮箱">
          <el-input disabled v-model="camerist.email" type="text"></el-input>
        </el-form-item>
        <el-form-item label="证件照">
          <img :src="camerist.avatar" style="width: 300px; height: 300px" />
        </el-form-item>
        <el-form-item label="年龄">
          <el-input-number
            disabled
            v-model="camerist.age"
            :min="1"
            :max="100"
            label="年龄"
          ></el-input-number>
        </el-form-item>
        <el-form-item label="性别">
          <el-radio-group disabled v-model="camerist.gender">
            <el-radio label="男"></el-radio>
            <el-radio label="女"></el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="申请理由">
          <el-input
            type="textarea"
            disabled
            v-model="camerist.introduce"
          ></el-input>
        </el-form-item>
        <el-form-item label="驳回理由">
          <el-input
            v-model="camerist.reason"
            :disabled="camerist.isPass !== 2"
            placeholder="驳回理由"
          ></el-input>
        </el-form-item>
      </el-form>
      <div v-if="camerist.isPass === 2">
        <el-button type="primary" @click="passApply">通过</el-button>
        <el-button type="primary" @click="noPassApply">不通过</el-button>
      </div>
    </el-card>
  </div>
</template>

<script>
import camerist from "@/api/camerist";

export default {
  data() {
    return {
      applyList: [],
      listLoading: true,
      camerist: {},
    };
  },
  created() {
    this.camerist = JSON.parse(this.$route.query.camerist);
  },
  methods: {
    passApply() {
      this.$confirm("此操作将通过该用户请求, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          camerist
            .pass(this.camerist.cameristId, this.camerist.reason)
            .then((res) => {
              if (res.success) {
                this.$message({
                  message: "已成功同意请求",
                  type: "success",
                });
                this.$router.push({ path: "/camerist/index" });
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    noPassApply() {
      console.log(this.camerist);
      if (
        this.camerist.reason === "" ||
        this.camerist.reason === undefined ||
        this.camerist.reason === null
      ) {
        this.$message({
          message: "请填写理由",
          type: "info",
        });
      } else {
        this.$confirm("此操作将驳回该用户请求, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            camerist
              .noPass(this.camerist.cameristId, this.camerist.userId)
              .then((res) => {
                if (res.success) {
                  this.$message({
                    message: "已成功驳回请求",
                    type: "success",
                  });
                  this.$router.push({ path: "/camerist/index" });
                }
              });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消",
            });
          });
      }
    },
  },
};
</script>
